function doViewItem(id)
{
	ajax.send('?m=items&a=view&suppressHeaders=1&item_id='+id, '',
		function (r) {
			var cd = Control('idItemDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd).show();
		}
	);
}

function doEditItem(id, extra)
{
	ajax.send('?m=items&a=edit&suppressHeaders=1&item_id='+id+''+extra, '',
		function (r) {
			var cd = Control('idItemDialog').create('div', 'popup', 'hidden');
			cd.innerHTML = r;
			Dialog(cd, 1).show();
			eval($('validation_rules').innerHTML);
		}
	);
}

function doCloseItem()
{
	Dialog('idItemDialog').hide();
}
/*
function doChangeDivision()
{
	$('idItemCostCenterName').value = '';
	$('idItemCostCenterId').value = 0;
}
*/
function doShowCostCenterSelector()
{
	//var c = $('idItemDivisionId');
	//var id = c.options[c.selectedIndex].value;
	var id=0;
	ajax.send('index.php?m=public&a=viewinfo&suppressHeaders=1&type=CostCenterList&id='+id, '',
		function(r) {
			var d = Control('idCostCentertSelector').create('div', 'topper', 'hidden');
			var error = r.indexOf('idCostCenterList') < 0;
			if (!error) {
				r = r.replace(/\n|\r/g,'');
				r = r.replace(/\<tr\>.*?\<\/tr\>/i,'');
				r = r.replace(/width="250px"/i, 'width="260px"');
				r = r.replace(/cellpadding="4"/i, 'cellpadding="0"');
			}
			d.innerHTML = r;
			Control(d).show();
			if (!error) initTree($('idCostCenterTree'));
			$('idItemDialog').onclick = function() {
				Control('idCostCentertSelector').destroy();
				this.onclick = undefined;
			}
			if (error) {
				Control(d).center();
			}
			else {
				var p = Control('idItemCostCenterName').position();
				Control(d).move(p.x + 3, p.y + 22);
			}
		}
	);
}
function doSelectCostCenter(id)
{
	$('idItemCostCenterId').value = id;
	$('idItemCostCenterName').value = unescape($('idCostCenterId['+id+']').getAttribute('value'));
	Control('idCostCentertSelector').destroy();
}
/*
function doChangeCosCenter()
{
	$('idResourceName').value = '';
	$('idResourceId').value = 0;
}
*/
function doSwitchTab(tab)
{
	if (tab.className == 'here') return;
	var c, i, r = tab.parentNode;
	for (i = 0; i < r.cells.length; i++) {
		if (r.cells[i].className == 'here') {
			c = r.cells[i];
			c.className = 'tab';
			break;
		}
	}
	tab.className = 'here';
	Control('id' + c.innerHTML).hide();
	Control('id' + tab.innerHTML).show();
}

function doValidateItemForm(frm) {
	return true;
}

function doDelete(id, name)	{
	if (confirm( "Do you want to delete "+ name)) {
		$('del_cc_id').value = id;
		f = $('MdFormDelete');
		f.del.value = id;
		f.submit();
	}
}

function doChangeType(frm, v, itemTaskTypes, itemTaskLogTypes, tasks, logs) {
	var row = $('idRowVat');
	var check = $('idRowCheck');
	var vat = frm.elements['item_vat_code'];
	var checkbox = frm.elements['item_be_check'];
	var isTask = false;
	var s = $('idItemGroup');
	var tb = $('idTabBox');
	for(i=0; i < itemTaskTypes.length; i++) {
		if (v == itemTaskTypes[i]) {
			row.style.display = "";
			row.style.visibility = "";
			check.style.display = "";
			check.style.visibility = "";
			vat.disabled = false;
			checkbox.disabled = false;
			isTask = true;
			tb.style.height = "200px";
			break;
		}
	}
	var isTaskLog = false;
	for(i=0; i < itemTaskLogTypes.length; i++) {
		if (v == itemTaskLogTypes[i]) {
			isTaskLog = true;
			break;
		}
	}
	s.options.length = 0;
	if (isTask) {
		for (i=0; i < tasks.length; i++) {
			s.options[i] = tasks[i];
		}
		return;
	}
	if (isTaskLog) {
		for (i=0; i < logs.length; i++) {
			s.options[i] = logs[i];
		}
	}
	row.style.display = "none";
	row.style.visibility = "hidden";
	check.style.display = "none";
	check.style.visibility = "hidden";
	vat.disabled = true;
	checkbox.disabled = true;
	tb.style.height = "160px";
}

function selectItemGroup(s, v) {
	for(var i = 0; i < s.options.length; i++) {
		var o = s.options[i];
		if (o.value == v) {
			o.selected = true;
			break;
		}
	}
}